package xyz.zhzby.cyzx.ucenter.controller;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xyz.zhzby.cyzx.servicebase.domain.RestResponse;
import xyz.zhzby.cyzx.ucenter.dto.request.CodeRequest;
import xyz.zhzby.cyzx.ucenter.dto.request.PasswordRequest;
import xyz.zhzby.cyzx.ucenter.dto.response.UserResponse;
import xyz.zhzby.cyzx.ucenter.entity.User;
import xyz.zhzby.cyzx.ucenter.service.IUserService;

/**
 * @author zby
 * @date 2021/12/16
 */
@RestController
@RequestMapping("/ucenter/user")
@ApiModel("用户操作信息相关API")
public class UserController {

    @Autowired
    private IUserService userService;

    @ApiOperation("获取当前用户信息")
    @GetMapping("")
    public RestResponse<UserResponse> getCurrentUserInfo() {
        return userService.getCurrentUserInfo();
    }

    @ApiOperation("修改当前用户信息（部分）")
    @PutMapping("")
    public RestResponse<String> updateInfo(@RequestBody User user) {
        return userService.updateInfo(user);
    }

    @ApiOperation("修改当前用户邮箱")
    @PutMapping("/email")
    public RestResponse<String> updateEmail(@RequestBody CodeRequest codeRequest) {
        return userService.updateEmail(codeRequest.getKey(), codeRequest.getCode());
    }

    @ApiOperation("修改当前用户手机")
    @PutMapping("/phone")
    public RestResponse<String> updatePhone(@RequestBody CodeRequest codeRequest) {
        return userService.updatePhone(codeRequest.getKey(), codeRequest.getCode());
    }

    @ApiOperation("修改当前用户头像")
    @PutMapping("/avatar")
    public RestResponse<String> updateAvatar(@RequestParam("avatar") String avatar) {
        return userService.updateAvatar(avatar);
    }

    @ApiOperation("修改当前用户密码")
    @PutMapping("/password")
    public RestResponse<String> updatePassword(@RequestBody PasswordRequest passwordRequest) {
        return userService.updatePassword(passwordRequest);
    }
}
